package com.sos.repository;

import com.sos.model.entity.Notification;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NotificationRepository extends JpaRepository<Notification, Long> {
    @Query("SELECT n FROM Notification n WHERE n.userId = ?1 ORDER BY n.createdTime DESC")
    List<Notification> findByUserIdOrderByCreatedTimeDesc(Long userId, Pageable pageable);

    @Query("SELECT n FROM Notification n WHERE n.id > ?1 AND n.userId = ?2 ORDER BY n.createdTime DESC")
    List<Notification> findAllByIdGreaterThanAndUserIdOrderByCreatedTimeDesc(Long sinceId, Long userId, Pageable pageable);

    // 根据ID和用户ID查找通知
    Notification findByIdAndUserId(Long id, Long userId);
}